﻿#ifndef TESTPLANBUILDER_H
#define TESTPLANBUILDER_H

#include <QHash>
#include <QSharedPointer>
#include <QVector>
#include "common/datatypes.h"

class TestPlanBuilder
{
public:
    TestPlanBuilder();
    ~TestPlanBuilder();

    // 从可编辑模板构建只读快照计划
    Exec::TestPlanPtr build(const TestTemplate &tpl);

    Exec::CurvePtr buildCurveFromAtt(const AttTableList &src, double val = 0, bool isConst = false);
    Exec::CurvePtr buildCurveFromTransducer(const TransducerTableList &src);
    Exec::CurvePtr makeAlignedCurve(const Exec::CurvePtr &src, const AxisScale xScale, const AxisScale yScale, const QVector<double> &gridHz);
    QVector<double> expandFreqs(const TestSubBand &sb,
                                const QVector<FreqTableConfig> *freqTbl /*nullable*/);

private:
    // 构建作用域缓存（同一构建过程内去重复用）
    QHash<int, Exec::HardwarePtr> hwCache_;  // key: hardwareTemplateID
    QHash<int, Exec::CurvePtr> curveCache_;  // 如果需要按表ID缓存曲线（Att/Transducer/Limit），可以用
    QHash<int, Exec::CalTablePtr> calCache_; // key: CalibrationTables_Meta.id

    // 解析/构建子函数
    Exec::HardwarePtr resolveHardware(int hardwareTemplateId);
    Exec::CurvePtr buildCurveFromLimit(const LimitLineList &src, const double offset, double val = 0, bool isConst = false);
    Exec::CalTablePtr resolveCalTable(int calMetaId);

    bool validateCalibrationData(const Exec::CalTablePtr &calTabl, const QVector<double> &calFreq);
};

#endif // TESTPLANBUILDER_H
